import common
import unittest

from DCOracle2.dco2 import OracleDate

class test_DCOracle2_connect(common.TestCase):

    def setUp(self):
        common.TestCase.setUp(self)
        self.c.execute("select * from emp")

    def test_cursorDescription(self):
        self.assertEqual(list(self.c.description),
                         [('EMPNO', 'NUMBER', 22, 22, 4, 0, 0),
                          ('ENAME', 'VARCHAR2', 10, 10, 0, 0, 1),
                          ('JOB', 'VARCHAR2', 9, 9, 0, 0, 1),
                          ('MGR', 'NUMBER', 22, 22, 4, 0, 1),
                          ('HIREDATE', 'DATE', 7, 7, 0, 0, 1),
                          ('SAL', 'NUMBER', 22, 22, 7, 2, 1),
                          ('COMM', 'NUMBER', 22, 22, 7, 2, 1),
                          ('DEPTNO', 'NUMBER', 22, 22, 2, 0, 1)])
        
    def test_fetchall(self):
        self.c.arraysize = 20

        r = self.c.fetchall()
        
        self.assertEqual(r,
                         [
            [7369, 'SMITH', 'CLERK', 7902, OracleDate(1980,12,17,0,0,0), 800.0, None, 20],
            [7499, 'ALLEN', 'SALESMAN', 7698, OracleDate(1981,2,20,0,0,0), 1600.0, 300.0, 30],
            [7521, 'WARD', 'SALESMAN', 7698, OracleDate(1981,2,22,0,0,0), 1250.0, 500.0, 30],
            [7566, 'JONES', 'MANAGER', 7839, OracleDate(1981,4,02,0,0,0), 2975.0, None, 20],
            [7654, 'MARTIN', 'SALESMAN', 7698, OracleDate(1981,9,28,0,0,0), 1250.0, 1400.0, 30],
            [7698, 'BLAKE', 'MANAGER', 7839, OracleDate(1981,5,1,0,0,0), 2850.0, None, 30],
            [7782, 'CLARK', 'MANAGER', 7839, OracleDate(1981,6,9,0,0,0), 2450.0, None, 10],
            [7788, 'SCOTT', 'ANALYST', 7566, OracleDate(1987,4,19,0,0,0), 3000.0, None, 20],
            [7839, 'KING', 'PRESIDENT', None, OracleDate(1981,11,17,0,0,0), 5000.0, None, 10],
            [7844, 'TURNER', 'SALESMAN', 7698, OracleDate(1981,9,8,0,0,0), 1500.0, 0.0, 30],
            [7876, 'ADAMS', 'CLERK', 7788, OracleDate(1987,5,23,0,0,0), 1100.0, None, 20],
            [7900, 'JAMES', 'CLERK', 7698, OracleDate(1981,12,3,0,0,0), 950.0, None, 30],
            [7902, 'FORD', 'ANALYST', 7566, OracleDate(1981,12,3,0,0,0), 3000.0, None, 20],
            [7934, 'MILLER', 'CLERK', 7782, OracleDate(1982,1,23,0,0,0), 1300.0, None, 10]
            ])

        self.assertEqual(str(r[0][4]),'1980-12-17 00:00:00')

if __name__ == '__main__':
    unittest.main()
